const express = require('express')
const router = express.Router()
const db = require('../databases/index')
router.get('/cates', (req, res) => {
    let sql = `select * from category `
    db(sql, (err, results) => {
        if (err) {
            throw err
        }
        res.send({
            status: 0,
            message: "获取文章分类列表成功！",
            data:results
        })

    })
})
// 删除
router.post('/deletecate/:id', (req, res) => {
    let sql =`delete from category where id =${req.params.id} `
    db(sql,(err,results)=>{
        if (err) {
            throw err
        }
        if (results.affectedRows !== 1 ) {
          res.send('删除文章分类失败！')  
        }
        res.send({
            status: 0,
            message: "删除文章分类成功！"
        })
    
    })
})





module.exports = router